import 'package:flutter/material.dart';
import '../Home/C/HomeController.dart';
import 'ClassifyController.dart';
import 'CartController.dart';
import 'MyController.dart';
class TabBarController extends StatefulWidget {
  const TabBarController({Key? key}) : super(key: key);

  @override
  _TabBarControllerState createState() => _TabBarControllerState();
}

class _TabBarControllerState extends State<TabBarController> {
  int _currentIndex = 0; //当前tab所在位置
  List _pageList=[
    HomeController(),
    ClassifyController(),
    CartController(),
    MyController(),
  ]; //4个子视图
  @override
  Widget build(BuildContext context) {
    //Scaffold布局的容器
    return Scaffold(
      appBar: AppBar(
        title: Text("jdShop"),//导航条文字
      ),
      // body: Text("我是首页"),
      body: this._pageList[this._currentIndex],//4个子视图
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: this._currentIndex,
          onTap: (index){
            setState(() {
              //切换Tab
              this._currentIndex=index;
            });
          },
          type:BottomNavigationBarType.fixed,//TabBar修复
          fixedColor:Colors.blue,//选中颜色
        items: [
          BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: "首页"
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.category),
              label: "分类"
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.shopping_cart),
              label: "购物车"
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.people),
              label: "我的"
          )
        ],
      ),
    );
  }
}
